home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / man.n / trace.n < prev    next >
Text File  |  1995-07-17  |  11KB  |  357 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/trace.n,v 1.3 93/06/16 16:36:39 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .\" The definitions below are for supplemental macros used in Tcl/Tk
  24. .\" manual entries.
  25. .\"
  26. .\" .HS name section [date [version]]
  27. .\"    Replacement for .TH in other man pages.  See below for valid
  28. .\"    section names.
  29. .\"
  30. .\" .AP type name in/out [indent]
  31. .\"    Start paragraph describing an argument to a library procedure.
  32. .\"    type is type of argument (int, etc.), in/out is either "in", "out",
  33. .\"    or "in/out" to describe whether procedure reads or modifies arg,
  34. .\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  35. .\"    needed;  use .AS below instead)
  36. .\"
  37. .\" .AS [type [name]]
  38. .\"    Give maximum sizes of arguments for setting tab stops.  Type and
  39. .\"    name are examples of largest possible arguments that will be passed
  40. .\"    to .AP later.  If args are omitted, default tab stops are used.
  41. .\"
  42. .\" .BS
  43. .\"    Start box enclosure.  From here until next .BE, everything will be
  44. .\"    enclosed in one large box.
  45. .\"
  46. .\" .BE
  47. .\"    End of box enclosure.
  48. .\"
  49. .\" .VS
  50. .\"    Begin vertical sidebar, for use in marking newly-changed parts
  51. .\"    of man pages.
  52. .\"
  53. .\" .VE
  54. .\"    End of vertical sidebar.
  55. .\"
  56. .\" .DS
  57. .\"    Begin an indented unfilled display.
  58. .\"
  59. .\" .DE
  60. .\"    End of indented unfilled display.
  61. .\"
  62. '\"    # Heading for Tcl/Tk man pages
  63. .de HS
  64. .ds ^3 \\0
  65. .if !"\\$3"" .ds ^3 \\$3
  66. .if '\\$2'cmds'       .TH \\$1 1 \\*(^3 \\$4
  67. .if '\\$2'lib'        .TH \\$1 3 \\*(^3 \\$4
  68. .if '\\$2'tcl'        .TH \\$1 n \\*(^3 Tcl "Tcl Built-In Commands"
  69. .if '\\$2'tk'         .TH \\$1 n \\*(^3 Tk "Tk Commands"
  70. .if '\\$2'tclc'        .TH \\$1 3 \\*(^3 Tcl "Tcl Library Procedures"
  71. .if '\\$2'tkc'         .TH \\$1 3 \\*(^3 Tk "Tk Library Procedures"
  72. .if '\\$2'tclcmds'         .TH \\$1 1 \\*(^3 Tk "Tcl Applications"
  73. .if '\\$2'tkcmds'         .TH \\$1 1 \\*(^3 Tk "Tk Applications"
  74. .if t .wh -1.3i ^B
  75. .nr ^l \\n(.l
  76. .ad b
  77. ..
  78. '\"    # Start an argument description
  79. .de AP
  80. .ie !"\\$4"" .TP \\$4
  81. .el \{\
  82. .   ie !"\\$2"" .TP \\n()Cu
  83. .   el          .TP 15
  84. .\}
  85. .ie !"\\$3"" \{\
  86. .ta \\n()Au \\n()Bu
  87. \&\\$1    \\fI\\$2\\fP    (\\$3)
  88. .\".b
  89. .\}
  90. .el \{\
  91. .br
  92. .ie !"\\$2"" \{\
  93. \&\\$1    \\fI\\$2\\fP
  94. .\}
  95. .el \{\
  96. \&\\fI\\$1\\fP
  97. .\}
  98. .\}
  99. ..
  100. '\"    # define tabbing values for .AP
  101. .de AS
  102. .nr )A 10n
  103. .if !"\\$1"" .nr )A \\w'\\$1'u+3n
  104. .nr )B \\n()Au+15n
  105. .\"
  106. .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  107. .nr )C \\n()Bu+\\w'(in/out)'u+2n
  108. ..
  109. '\"    # BS - start boxed text
  110. '\"    # ^y = starting y location
  111. '\"    # ^b = 1
  112. .de BS
  113. .br
  114. .mk ^y
  115. .nr ^b 1u
  116. .if n .nf
  117. .if n .ti 0
  118. .if n \l'\\n(.lu\(ul'
  119. .if n .fi
  120. ..
  121. '\"    # BE - end boxed text (draw box now)
  122. .de BE
  123. .nf
  124. .ti 0
  125. .mk ^t
  126. .ie n \l'\\n(^lu\(ul'
  127. .el \{\
  128. .\"    Draw four-sided box normally, but don't draw top of
  129. .\"    box if the box started on an earlier page.
  130. .ie !\\n(^b-1 \{\
  131. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  132. .\}
  133. .el \}\
  134. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  135. .\}
  136. .\}
  137. .fi
  138. .br
  139. .nr ^b 0
  140. ..
  141. '\"    # VS - start vertical sidebar
  142. '\"    # ^Y = starting y location
  143. '\"    # ^v = 1 (for troff;  for nroff this doesn't matter)
  144. .de VS
  145. .mk ^Y
  146. .ie n 'mc \s12\(br\s0
  147. .el .nr ^v 1u
  148. ..
  149. '\"    # VE - end of vertical sidebar
  150. .de VE
  151. .ie n 'mc
  152. .el \{\
  153. .ev 2
  154. .nf
  155. .ti 0
  156. .mk ^t
  157. \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  158. .sp -1
  159. .fi
  160. .ev
  161. .\}
  162. .nr ^v 0
  163. ..
  164. '\"    # Special macro to handle page bottom:  finish off current
  165. '\"    # box/sidebar if in box/sidebar mode, then invoked standard
  166. '\"    # page bottom macro.
  167. .de ^B
  168. .ev 2
  169. 'ti 0
  170. 'nf
  171. .mk ^t
  172. .if \\n(^b \{\
  173. .\"    Draw three-sided box if this is the box's first page,
  174. .\"    draw two sides but no top otherwise.
  175. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  176. .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  177. .\}
  178. .if \\n(^v \{\
  179. .nr ^x \\n(^tu+1v-\\n(^Yu
  180. \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  181. .\}
  182. .bp
  183. 'fi
  184. .ev
  185. .if \\n(^b \{\
  186. .mk ^y
  187. .nr ^b 2
  188. .\}
  189. .if \\n(^v \{\
  190. .mk ^Y
  191. .\}
  192. ..
  193. '\"    # DS - begin display
  194. .de DS
  195. .RS
  196. .nf
  197. .sp
  198. ..
  199. '\"    # DE - end display
  200. .de DE
  201. .fi
  202. .RE
  203. .sp .5
  204. ..
  205. .HS trace tcl
  206. .BS
  207. '\" Note:  do not modify the .SH NAME line immediately below!
  208. .SH NAME
  209. trace \- Monitor variable accesses
  210. .SH SYNOPSIS
  211. \fBtrace \fIoption\fR ?\fIarg arg ...\fR?
  212. .BE
  213.  
  214. .SH DESCRIPTION
  215. .PP
  216. This command causes Tcl commands to be executed whenever certain operations are
  217. invoked.  At present, only variable tracing is implemented. The
  218. legal \fIoption\fR's (which may be abbreviated) are:
  219. .TP
  220. \fBtrace variable \fIname ops command\fR
  221. Arrange for \fIcommand\fR to be executed whenever variable \fIname\fR
  222. is accessed in one of the ways given by \fIops\fR.  \fIName\fR may
  223. refer to a normal variable, an element of an array, or to an array
  224. as a whole (i.e. \fIname\fR may be just the name of an array, with no
  225. parenthesized index).  If \fIname\fR refers to a whole array, then
  226. \fIcommand\fR is invoked whenever any element of the array is
  227. manipulated.
  228. .RS
  229. .LP
  230. \fIOps\fR indicates which operations are of interest, and consists of
  231. one or more of the following letters:
  232. .RS
  233. .TP
  234. \fBr\fR
  235. Invoke \fIcommand\fR whenever the variable is read.
  236. .TP
  237. \fBw\fR
  238. Invoke \fIcommand\fR whenever the variable is written.
  239. .TP
  240. \fBu\fR
  241. Invoke \fIcommand\fR whenever the variable is unset.  Variables
  242. can be unset explicitly with the \fBunset\fR command, or
  243. implicitly when procedures return (all of their local variables
  244. are unset).  Variables are also unset when interpreters are
  245. deleted, but traces will not be invoked because there is no
  246. interpreter in which to execute them.
  247. .RE
  248. .LP
  249. When the trace triggers, three arguments are appended to
  250. \fIcommand\fR so that the actual command is as follows:
  251. .DS C
  252. \fIcommand name1 name2 op\fR
  253. .DE
  254. \fIName1\fR and \fIname2\fR give the name(s) for the variable
  255. being accessed:  if the variable is a scalar then \fIname1\fR
  256. gives the variable's name and \fIname2\fR is an empty string;
  257. if the variable is an array element then \fIname1\fR gives the
  258. name of the array and name2 gives the index into the array;
  259. if an entire array is being deleted and the trace was registered
  260. on the overall array, rather than a single element, then \fIname1\fR
  261. gives the array name and \fIname2\fR is an empty string.
  262. \fIOp\fR indicates what operation is being performed on the
  263. variable, and is one of \fBr\fR, \fBw\fR, or \fBu\fR as
  264. defined above.
  265. .LP
  266. \fICommand\fR executes in the same context as the code that invoked
  267. the traced operation:  if the variable was accessed as part of a
  268. Tcl procedure, then \fIcommand\fR will have access to the same
  269. local variables as code in the procedure.  This context may be
  270. different than the context in which the trace was created.
  271. If \fIcommand\fR invokes a procedure (which it normally does) then
  272. the procedure will have to use \fBupvar\fR or \fBuplevel\fR if it
  273. wishes to access the traced variable.
  274. Note also that \fIname1\fR may not necessarily be the same as the name
  275. used to set the trace on the variable;  differences can occur if
  276. the access is made through a variable defined with the \fBupvar\fR
  277. command.
  278. .LP
  279. For read and write traces, \fIcommand\fR can modify
  280. the variable to affect the result of the traced operation.
  281. If \fIcommand\fR modifies the value of a variable during a
  282. read or write trace, then the new value will be returned as the
  283. result of the traced operation.
  284. The return value from  \fIcommand\fR is ignored except that
  285. if it returns an error of any sort then the traced operation
  286. also returns an error with
  287. .VS
  288. the same error message returned by the trace command
  289. .VE
  290. (this mechanism can be used to implement read-only variables, for
  291. example).
  292. For write traces, \fIcommand\fR is invoked after the variable's
  293. value has been changed; it can write a new value into the variable
  294. to override the original value specified in the write operation.
  295. To implement read-only variables, \fIcommand\fR will have to restore
  296. the old value of the variable.
  297. .LP
  298. While \fIcommand\fR is executing during a read or write trace, traces
  299. on the variable are temporarily disabled.
  300. This means that reads and writes invoked by
  301. \fIcommand\fR will occur directly, without invoking \fIcommand\fR
  302. (or any other traces) again.
  303. .VS
  304. However, if \fIcommand\fR unsets the variable then unset traces
  305. will be invoked.
  306. .VE
  307. .LP
  308. When an unset trace is invoked, the variable has already been
  309. deleted:  it will appear to be undefined with no traces.
  310. If an unset occurs because of a procedure return, then the
  311. trace will be invoked in the variable context of the procedure
  312. being returned to:  the stack frame of the returning procedure
  313. will no longer exist.
  314. Traces are not disabled during unset traces, so if an unset trace
  315. command creates a new trace and accesses the variable, the
  316. trace will be invoked.
  317. .VS
  318. Any errors in unset traces are ignored.
  319. .VE
  320. .LP
  321. If there are multiple traces on a variable they are invoked
  322. in order of creation, most-recent first.
  323. If one trace returns an error, then no further traces are
  324. invoked for the variable.
  325. If an array element has a trace set, and there is also a trace
  326. set on the array as a whole, the trace on the overall array
  327. is invoked before the one on the element.
  328. .LP
  329. Once created, the trace remains in effect either until the
  330. trace is removed with the \fBtrace vdelete\fR command described
  331. below, until the variable is unset, or until the interpreter
  332. is deleted.
  333. Unsetting an element of array will remove any traces on that
  334. element, but will not remove traces on the overall array.
  335. .LP
  336. This command returns an empty string.
  337. .RE
  338. .TP
  339. \fBtrace vdelete \fIname ops command\fR
  340. If there is a trace set on variable \fIname\fR with the
  341. operations and command given by \fIops\fR and \fIcommand\fR,
  342. then the trace is removed, so that \fIcommand\fR will never
  343. again be invoked.
  344. Returns an empty string.
  345. .TP
  346. \fBtrace vinfo \fIname\fR
  347. Returns a list containing one element for each trace
  348. currently set on variable \fIname\fR.
  349. Each element of the list is itself a list containing two
  350. elements, which are the \fIops\fR and \fIcommand\fR associated
  351. with the trace.
  352. If \fIname\fR doesn't exist or doesn't have any traces set, then
  353. the result of the command will be an empty string.
  354.  
  355. .SH KEYWORDS
  356. read, variable, write, trace, unset
  357.